package letsjava.pattern.flyweight;

import java.util.Hashtable;

public class FlyweightFactory {
	// Flyweight pool
	private Hashtable flyweights = new Hashtable();

	public Flyweight getFlyweight(Object key) {
		Flyweight flyweight = (Flyweight) flyweights.get(key);
		if (flyweight == null) {
			// 产生新的ConcreteFlyweight
			flyweight = new ConcreteFlyweight();
			flyweights.put(key, flyweight);
		}
		return flyweight;
	}
	public static void main(String[] args){
		FlyweightFactory a = new FlyweightFactory();
		a.getFlyweight("tang");
		a.getFlyweight("tang");
		a.getFlyweight("tang2");
		
	}
}